
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[EBAS_GRUPPE_STUDERENDE]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[EBAS_GRUPPE_STUDERENDE]
GO

CREATE TABLE [dbo].[EBAS_GRUPPE_STUDERENDE] (
	[GUID]  uniqueidentifier ROWGUIDCOL  NOT NULL ,
	[STUDERENDE_GUID] [uniqueidentifier] NOT NULL ,
	[GRUPPE_GUID] [uniqueidentifier] NOT NULL ,
	[TILMELDT_DATO] [datetime] NOT NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[EBAS_GRUPPE_STUDERENDE] WITH NOCHECK ADD 
	CONSTRAINT [PK_EBAS_GRUPPE_STUDERENDE] PRIMARY KEY  CLUSTERED 
	(
		[GUID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[EBAS_GRUPPE_STUDERENDE] WITH NOCHECK ADD 
	CONSTRAINT [DF_EBAS_GRUPPE_STUDERENDE_TILMELDT_DATO] DEFAULT (getdate()) FOR [TILMELDT_DATO]
GO

 CREATE  UNIQUE  INDEX [IDX_UQ_EBAS_GRUPPE_STUDERENDE] ON [dbo].[EBAS_GRUPPE_STUDERENDE]([STUDERENDE_GUID], [GRUPPE_GUID]) ON [PRIMARY]
GO

ALTER TABLE [dbo].[EBAS_GRUPPE_STUDERENDE] ADD 
	CONSTRAINT [FK_EBAS_GRUPPE_STUDERENDE_EBAS_GRUPPE] FOREIGN KEY 
	(
		[GRUPPE_GUID]
	) REFERENCES [dbo].[EBAS_GRUPPE] (
		[GUID]
	),
	CONSTRAINT [FK_EBAS_GRUPPE_STUDERENDE_EBAS_STUDERENDE] FOREIGN KEY 
	(
		[STUDERENDE_GUID]
	) REFERENCES [dbo].[EBAS_STUDERENDE] (
		[GUID]
	)
GO
